#define _CRT_SECURE_NO_WARNINGS

#include<Windows.h>
#include<time.h>
#include<stdio.h>
#include<stdlib.h>
void menu()
{
	printf("**************************************\n");
	printf("************ gussing game ************\n");
	printf("********** press Y to start **********\n");
	printf("********** press N to exit ***********\n");
	printf("**************************************\n");
	printf("Start?(Y/N)\n");
}

unsigned int seed()
{
	unsigned int b = time(NULL);
	return b;
}

int game()
{
	srand(seed());
	int r = rand();
	char input = '0';
	scanf("%c", &input);


	if (input == 'Y')
	{
		printf("Input a number\n");
		int g = 0;

		for (;;)
		{
			getchar();
			scanf("%d", &g);
			if (g < r)
			{
				printf("Be bigger.\n");
			}
			else if (g > r)
			{
				printf("Be smaller.\n");
			}
			else if (g == r)
			{
				printf("You win!\n");
				for (;;)
				{

					printf("Restart?(Y/N)\n");
					char re = '0';
					getchar();
					scanf("%c", &re);
					if (re == 'Y')
					{
						return 1;
					}
					else if (re == 'N')
					{
						printf("Exit.");
						return 0;
					}
					else
					{
						printf("Error.\n");
						continue;
					}
				}
			}

		}

	}
	else if (input == 'N')
	{
		printf("Exit.");
		return 0;
	}
	else
	{
		printf("Error.");
	}

}

int main()
{
	for (;;)
	{
		system("cls");
		menu();
		int b = game();

		if (b == 0)
		{
			break;
		}
		else if (b == 1)
		{
			continue;
		}
	}
	return 0;
}
